<?php

class HomeController extends Controller
{
	public function actionIndex()
	{
		$member = Member::model()->findAll(' 1=1 order by created desc limit 4');
		foreach ($member as $rsmember){
			$newMember .= "<div>
							<div>
								<img width='150' vspace='10' hspace='10' height='150' src='".Yii::app()->baseUrl."/upload/fotoMember/".$rsmember->foto."'>
							</div>
							<div>Joined : ".$rsmember->created."</div>
							<div>profile | awards | gears </div>
					  </div>";
		}
		
		$grup = Groups::model()->findAll(' 1=1 order by created desc limit 4');
		foreach($grup as $rsgrup){
		$newGroup .= "<div>
							<div>
								<img width='150' vspace='10' hspace='10' height='150' src='".Yii::app()->baseUrl."/upload/fotoGroup/".$rsgrup->foto."'>
							</div>
							<div>Joined : ".$rsgrup->created."</div>
							<div>profile | awards | gears </div>
					  </div>";
		}
		
		$tabs1 = array(
			array('id' => 'newMember', 'label' => 'New Member', 'content' => $newMember),
			array('id' => 'newGroup', 'label' => 'New Group', 'content' => $newGroup),
		);
		
		$this->render('index',array(
				'tabs1' => $tabs1,
		));
	}
	
	public function actionArea()
	{
		Yii::app()->clientScript->scriptMap['*.js'] = false;
		Yii::app()->clientScript->scriptMap['*.css'] = false;
		$prov = Provinsi::model()->findAll();
		$response = array();
		foreach($prov as $rsprov =>$r){
			array_push($response, array(
                "id_provinsi"=>$r['id_provinsi']
                , "id_country"=>$r['id_country']
                , "name_prov"=>$r['name_prov']
                )
            );
		}
		echo json_encode($response);
	}
	
	public function actionRegion()
	{
		Yii::app()->clientScript->scriptMap['*.js'] = false;
		Yii::app()->clientScript->scriptMap['*.css'] = false;
		$id = $_GET['id'];
		$kab = Kabupaten::model()->findAll('id_provinsi ='.$id);
		$response = array();
		foreach($kab as $rskab =>$r){
			array_push($response, array(
                "id_kab"=>$r['id_kab']
                , "id_provinsi"=>$r['id_provinsi']
                , "name_kab"=>$r['name_kab']
                )
            );
		}
		echo json_encode($response);
	}
	
	public function actionCourse()
	{
		Yii::app()->clientScript->scriptMap['*.js'] = false;
		Yii::app()->clientScript->scriptMap['*.css'] = false;
		$id = $_GET['id'];
		$course = GolfLand::model()->findAll('id_kab ='.$id);
		$response = array();
		foreach($course as $rscourse =>$r){
			array_push($response, array(
                "id_golf"=>$r['id_golf']
                , "id_kab"=>$r['id_kab']
                , "name"=>$r['name']
                )
            );
		}
		echo json_encode($response);
	}
	
	
}
?>